package com.chris.libs.base.x.mvpp.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.lifecycle.LifecycleObserver;

import com.chris.libs.base.x.mvpp.R;

import java.io.Serializable;
import java.util.Map;

/**
 * @author Chris Chan
 * on 2019/7/9 17:14
 * use for:
 */
public abstract class BaseMvppFragment extends BaseInjectFragment {
    protected LifecycleObserver observer;

    @Override
    public void init(View view, Bundle savedInstanceState) {
        doProxy();
    }
    /**
     * 托管
     */
    public abstract void doProxy();

    @Override
    public void startActivity(Class<?> targerActivityClass) {
        super.startActivity(targerActivityClass);
    }

    @Override
    public void startActivityAndFinished(Class<?> targerActivityClass) {
        super.startActivityAndFinished(targerActivityClass);
    }

    @Override
    public void startActivityWithExtra(Class<?> clazz, String key, Serializable value) {
        super.startActivityWithExtra(clazz, key, value);
    }

    @Override
    public void startActivityWithExtraMap(Class<?> clazz, Map<String, Serializable> map) {
        super.startActivityWithExtraMap(clazz, map);
    }

    @Override
    public void startActivityForResult(Intent intent, int requestCode) {
        super.startActivityForResult(intent, requestCode);
    }

    @Override
    public void startActivityForResult(Class<?> clazz, int requestCode) {
        super.startActivityForResult(clazz, requestCode);
    }

    @Override
    public void finishActivity() {
        super.finishActivity();
    }

    @Override
    protected void afterStartActivity() {
        requireActivity().overridePendingTransition(R.anim.bts_anim_act_side_right_in, R.anim.bts_anim_act_side_left_out);
    }

    protected void addObserver(LifecycleObserver observer) {
        getLifecycle().addObserver(observer);
    }

    @Override
    public void onDestroy() {
        if (null != this.observer) {
            getLifecycle().removeObserver(this.observer);
        }
        super.onDestroy();
    }
}
